package com.hzlj.position.locate.controller.notify;


import cn.hutool.core.date.DateUtil;
import com.fz.common.base.core.JsonUtils;
import com.fz.common.base.dto.ResultDTO;
import com.hzlj.common.message.common.dto.message.MessageNotifyDTO;
import com.hzlj.position.locate.service.ReportInspectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 核验通知结果通知接口
 */
@Slf4j
@RestController
@RequestMapping("/position/report/message/notify")
public class ReportMessageNotifyController {

    @Resource
    private ReportInspectionService reportInspectionService;

    /**
     * 点验-收到消息回调
     */
    @PostMapping("/inspection")
    public ResultDTO<String> singleCallResult(@RequestBody MessageNotifyDTO notify) {
        log.info("【核查】收到消息回调:{}", JsonUtils.obj2json(notify));
        Map<String, Object> map = JsonUtils.json2map(notify.getExt().getParams());
        String belongDay = (String) map.get("belongDay");
        notify.getExt().setParams(null);

        //转发通知
        reportInspectionService.updateMessageNoticeExt(
                notify.getServiceId(),
                DateUtil.parseDate(belongDay),
                notify
        );
        return ResultDTO.ok();
    }

}

